package breeze.pixel.weather.apps_util.transformation;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;

import java.security.MessageDigest;

public class AppBrightnessTransformation extends BitmapTransformation {

    private int brightness;

    public AppBrightnessTransformation(int brightness) {
        this.brightness = brightness;
    }

    @Override
    protected Bitmap transform(BitmapPool pool, Bitmap bit, int outWidth, int outHeight) {
        Bitmap bmp = Bitmap.createBitmap(bit.getWidth(), bit.getHeight(),
                bit.getConfig());
        ColorMatrix cMatrix = new ColorMatrix();
        cMatrix.set(new float[]{1, 0, 0, 0, brightness, 0, 1,
                0, 0, brightness,// 改变亮度
                0, 0, 1, 0, brightness, 0, 0, 0, 1, 0});

        Paint paint = new Paint();
        paint.setColorFilter(new ColorMatrixColorFilter(cMatrix));

        Canvas canvas2 = new Canvas(bmp);
        // 在Canvas上绘制一个已经存在的Bitmap。这样，dstBitmap就和srcBitmap一摸一样了
        canvas2.drawBitmap(bit, 0, 0, paint);
        return bmp;
    }

    @Override
    public void updateDiskCacheKey(MessageDigest messageDigest) {

    }
}
